package com.eascs.admin.o2o.collectRecords.controller;

import java.text.DecimalFormat;
import java.text.Format;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.alibaba.dubbo.config.annotation.Reference;
import com.eascs.admin.common.controller.BaseMasterViewController;
import com.eascs.admin.o2o.collectRecords.entity.CollectRecordsVo;
import com.eascs.admin.o2o.collectRecords.service.CollectRecordsService;
import com.eascs.app.dao.PageResult;
import com.eascs.common.util.UrlUtil;
import com.eascs.site.page.PaginationInfo;
import com.eascs.site.page.SelectDataOption;
import com.eascs.site.view.ViewContext;
import com.eascs.tag.MenuTag;
import com.eascs.web.sso.User;
import com.eascs.web.sso.UserHolder;
import com.eascs.workflow.common.entity.sys.ActOrgEntity;
import com.eascs.workflow.common.service.sys.SysOrgService;

@Controller
@RequestMapping("/collectRecords")
public class CollectRecordsController extends BaseMasterViewController {
	@Reference
	SysOrgService sysOrgService;
	@Autowired
	private CollectRecordsService collectRecordsService;

	/**
	 * 
	 * @author LQ
	 * @deprecated loan-12986 清收记录查询
	 * @date 2018年1月22日
	 */
	@RequestMapping("/list")
	public String allList(CollectRecordsVo vo) {
		ViewContext.put(MenuTag.CURRENT_MENU_CODE, "CollectRecords");
		vo.setPageSize(10);
		 List<ActOrgEntity> orgProvince = sysOrgService.getOrgProvince();
		 ViewContext.put("ActOrgEntitys", orgProvince);//省区
		String url = "/collectRecords/list";
		String billCode = vo.getBillCode() == null ? "" : vo.getBillCode();
		String loanerName = vo.getLoanerName() == null ? "" : vo.getLoanerName();
		String loanBank = vo.getLoanBank() == null ? "" : vo.getLoanBank();
		String collector = vo.getCollector() == null ? "" : vo.getCollector();//清收人
		String operatorName = vo.getOperatorName() == null ? "" : vo.getOperatorName();//信贷经理
		String provinceCode = vo.getProvinceCode() == null ? "" : vo.getProvinceCode();//省区code
		url = UrlUtil.appendUrl(url, "billCode", billCode);
		url = UrlUtil.appendUrl(url, "loanerName", loanerName);
		url = UrlUtil.appendUrl(url, "loanBank", loanBank);
		url = UrlUtil.appendUrl(url, "collector", collector);
		url = UrlUtil.appendUrl(url, "operatorName", operatorName);
		url = UrlUtil.appendUrl(url, "provinceCode", provinceCode);
		url = url + "&pageIndex=";
		// == 菜单权限?
		List<User> users = sysOrgService.checkDataPermission(UserHolder.getUser().getNo());
		String no = "";
		if (users != null) {
			for (User user : users) {
				no += user.getNo() + ",";
			}
		}
		if (!"".equals(no)) {
			if (",".equals(no.substring(no.length() - 1, no.length()))) {
				no = no.substring(0, no.length() - 1);
			}
		}
		vo.setUsersno(no);
		// ==
		PageResult<Object[]> pageResult = collectRecordsService.getListByPage(vo);// 按页获取列表
		//以后待改--------
//		String titles[] = { "贷款单号", "借款人", "信贷经理", "省区", "放款银行", "回款时间", "回款金额" };
//		Format[] formats = new Format[] { null, null, null, null, null, null, new DecimalFormat(",##0.00")};
		String titles[] = { "贷款单号", "借款人", "信贷经理", "省区", "放款银行", "回款时间", "回款金额", "清收人", "清收系数", "回款类型" };
		Format[] formats = new Format[] { null, null, null, null, null, null, new DecimalFormat(",##0.00"), null, null, null};
//		SelectDataOption[] selectDataOptions = { null,null,null, new SelectDataOption("PROVINCE"), new SelectDataOption("BANKTYPEO2O"), null, null, null, null, null};
		PaginationInfo paginationInfo = new PaginationInfo(pageResult, titles, url);
		paginationInfo.setBuildPagingNavigation(true);
		paginationInfo.setFirstRenderColumnIndex(4);
//		paginationInfo.setSelectDataOptions(selectDataOptions);
		paginationInfo.setFormats(formats);
		ViewContext.put("paginationInfo", paginationInfo);
		ViewContext.put("vo", vo);
		return "/collectRecords/list";
	}
	// @RequestMapping("/index)

}
